﻿using System.Collections.Generic;
using System.Web.Mvc;

using Gx.Common;
using Gx.Model.Enums;
using Gx.Bll.OtherBll;
using Gx.Model.Entity;
using Gx.Model.Other;
using Gx.Bll.Manage;
using Gx.Model;
using Gx.Model.ViewModel;
using System.Web.UI.WebControls;
using System;

namespace Gx.ColdWarehouseErp.Controllers
{
    /// <summary>
    /// 员工基本信息
    /// </summary>
    public class EmployeeInfoController : BaseController
    {

        readonly B_EmployeeInfoBll employeeBll = new B_EmployeeInfoBll();
        readonly TreeViewBll tvBll = new TreeViewBll();

        public ActionResult EmployeeList()
        {
            return View();
        }

        public JsonResult GetEmployeeList(EmployeeInfoInput input, int page, int rows)
        {
            List<B_EmployeeInfo> list = employeeBll.GetB_EmployeeInfoList(input, page, rows, out int TotalCount);
            return Json(new { total = TotalCount, rows = list });
        }

        [HttpGet]
        public ActionResult AddEmployee()
        {
            return View();
        }

        [HttpPost]
        public ActionResult AddEmployee(B_EmployeeInfo Employee)
        {
            ReturnModel r = employeeBll.AddEmployeeInfo(Employee);
            return Json(r);
        }

        [HttpPost]
        public ActionResult EditEmployee(B_EmployeeInfo Employee)
        {
            ReturnModel r = employeeBll.EditEmployeeInfo(Employee);
            return Json(r);
        }


        [HttpPost]
        public ActionResult DelEmployee(int id)
        {
            ReturnModel r = employeeBll.DelEmployeeInfo(id);
            return Json(r);
        }


        /// <summary>
        /// 获取员工前10条数据
        /// </summary>
        /// <param name="q"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetEmployeeInfoListCombogrid(string q)
        {
            List<B_EmployeeInfo> ebList = employeeBll.GetE_EmployeeInfoListLikeFront10(q);
            return Json(ebList);
        }

        /// <summary>
        /// 获取部门树形结构json
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public JsonResult GetDepComBoTreeJson()
        {
            List<Model.Other.TreeView> tvList = tvBll.GetDepJson();
            return Json(tvList, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 根据部门Id初始化级别
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetLevelComboBoxJson(int depId)
        {
            List<E_DepLevelInfo> dlList = new E_DepLevelInfoBll().GetE_DepLevelInfoList(depId);
            return Json(dlList);
        }

        /// <summary>
        /// 根据枚举类型返回json格式数据
        /// </summary>
        /// <param name="enmuName"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult InitDictInfoList(string enmuName)
        {
            int dataType = EnumHelper.GetDataTypeValue<DictEnmus>(enmuName);
            List<M_DictInfo> dList = new M_DictInfoBll().GetDictInfoList(dataType);
            return Json(dList);
        }


        /// <summary>
        /// 充值密码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult RestPassWord(RestPassWordInput input)
        {
            ReturnModel r = employeeBll.RestPassWord(input);
            return Json(r);
        }


        /// <summary>
        /// 获取员工与仓库的关系
        /// </summary>
        /// <param name="EmployeeId"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetUserWareHouseList(int EmployeeId)
        {
            List<int> list = employeeBll.GetUserWareHouseList(EmployeeId);
            return Json(list);
        }

        /// <summary>
        /// 添加仓库与人员关系
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult AddUserWareHouse(UserWareHouseInput input)
        {
            ReturnModel r = employeeBll.AddUserWareHouse(input);
            return Json(r);
        }

    }
}
